#include <string>
#include <vector>
#include <filesystem>
#include "unzip_utils.h"

using namespace std;

VecData decompress(VecData::const_iterator begin, VecData::const_iterator end) {
    VecData decompressed;
    auto it = begin;

    while (it < end) {
        if (*it >> 7) { // If highest bit is 1
            int rep_len = *it & 0x7F;
            decompressed.insert(decompressed.cend(), rep_len, *(it + 1));
            it += 2;
        } else {
            int unrep_len = static_cast<unsigned char>(*it);
            decompressed.insert(decompressed.cend(), it + 1, it + 1 + unrep_len);
            it += 1 + unrep_len;
        }
    }

    return decompressed;
}

string get_parent_path(const string &path) {
    return filesystem::path(path).parent_path().string();
}
